//定位全屏
@mixin allcover {
    position: absolute;
    top: 0;
    right: 0;
}

//transform上下左右居中
@mixin ct {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

//定位上下左右居中
@mixin ctp($width, $height) {
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -$height/2;
    margin-left: -$width/2;
}

//flex上下左右剧中
@mixin fct() {
    display: flex;
    justify-content: center;
    align-items: center;
}

//定位上下居中
@mixin tb {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

//flex上下剧中
@mixin ftb {
    display: flex;
    align-items: center;
}

//定位左右居中
@mixin lr {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

//flex左右剧中
@mixin flr() {
    display: flex;
    justify-content: center;
}

//宽高
@mixin wh($width, $height) {
    width: $width;
    height: $height;
}

//字体大小、行高、字体
@mixin ft($size, $line-height) {
    font-size: $size;
    line-height: $line-height;
}

//字体大小，颜色
@mixin sc($size, $color) {
    font-size: $size;
    color: $color;
}

//flex 布局和 子元素 对其方式
@mixin fj($type: space-between) {
    display: flex;
    justify-content: $type;
}

//2倍图、3倍图，默认2倍图
@mixin bg-image($url) {
    background-image: url("./images/"+ $url + "@2x.png");

    @media only screen and (-webkit-min-device-pixel-ratio: 2),
    only screen and (min-device-pixel-ratio: 2) {
        background-image: url("./images/"+ $url + "@3x.png");
    }
}

//多行超出省略号
@mixin ellipsis($line: 2, $line-height: 1.2) {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: $line;
    line-height: $line-height;
}

@mixin modalbg($color-bg: rgba(0, 0, 0, 0.2)) {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: $color-bg;
}

@mixin flex($direction: column, $wrap: nowrap) {
    display: flex;
    flex-direction: $direction;
    flex-wrap: $wrap;
}

@mixin clear() {
    &:after {
        content: '.';
        clear: both;
        display: block;
        width: 0;
        height: 0;
        visibility: hidden;
    }
}

/* 倍图 */
@mixin bg-image($url) {
    background-image: url($url + "@2x.png");
    /* 设备像素比为 3 */
    @media only screen and (-webkit-min-device-pixel-ratio: 3),
    only screen and (min-device-pixel-ratio: 3) {
        background-image: url($url + "@3x.png")
    }
}

/* 1像素边框 */

@mixin border($width: 1px, $border-color: #999, $border-radius: initial) {
    position: relative;

    /* 默认 */
    &:after {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        border: $width solid $border-color;
        border-radius: $border-radius;
        box-sizing: border-box;
        width: 100%;
        height: 100%;
    }

    /* 设备像素比为 2 */
    @media only screen and (-webkit-min-device-pixel-ratio: 2),
    only screen and (min-device-pixel-ratio: 2) {
        &:after {
            width: 200%;
            height: 200%;
            transform: scale(0.5);
            transform-origin: left top;
        }
    }

    /* 设备像素比为 3 */
    @media only screen and (-webkit-min-device-pixel-ratio: 3),
    only screen and (min-device-pixel-ratio: 3) {
        &:after {
            width: 300%;
            height: 300%;
            transform: scale(0.333333);
            transform-origin: left top;
        }
    }
}

@mixin border-bottom($height: 1px, $width: 100%, $border-color: #999) {
    position: relative;

    /* 默认 */
    &:after {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        width: $width;
        height: $height;
        background-color: $border-color;
    }

    /* 设备像素比为 2 */
    @media only screen and (-webkit-min-device-pixel-ratio: 2),
    only screen and (min-device-pixel-ratio: 2) {
        &:after {
            background-color: $border-color;
            transform: scaleY(0.5);
        }
    }

    /* 设备像素比为 3 */
    @media only screen and (-webkit-min-device-pixel-ratio: 3),
    only screen and (min-device-pixel-ratio: 3) {
        &:after {
            background-color: $border-color;
            transform: scaleY(0.333333);
        }
    }
}

@mixin border-top($height: 1px, $width: 100%, $border-color: #999) {
    position: relative;

    /* 默认 */
    &:after {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        width: $width;
        height: $height;
        background-color: $border-color;
    }

    /* 设备像素比为 2 */
    @media only screen and (-webkit-min-device-pixel-ratio: 2),
    only screen and (min-device-pixel-ratio: 2) {
        &:after {
            transform: scaleY(0.5);
        }
    }

    /* 设备像素比为 3 */
    @media only screen and (-webkit-min-device-pixel-ratio: 3),
    only screen and (min-device-pixel-ratio: 3) {
        &:after {
            transform: scaleY(0.333333);
        }
    }
}

@mixin border-right($height: 100%, $width: 1px, $border-color: #999) {
    position: relative;

    /* 默认 */
    &:after {
        content: "";
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: $width;
        height: $height;
        background-color: $border-color;
    }

    /* 设备像素比为 2 */
    @media only screen and (-webkit-min-device-pixel-ratio: 2),
    only screen and (min-device-pixel-ratio: 2) {
        &:after {
            transform: scaleX(0.5);
        }
    }

    /* 设备像素比为 3 */
    @media only screen and (-webkit-min-device-pixel-ratio: 3),
    only screen and (min-device-pixel-ratio: 3) {
        &:after {
            transform: scaleX(0.333333);
        }
    }
}

@mixin border-left($height: 100%, $width: 1px, $border-color: #999) {
    position: relative;

    /* 默认 */
    &:after {
        content: "";
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: $width;
        height: $height;
        background-color: $border-color;
    }

    /* 设备像素比为 2 */
    @media only screen and (-webkit-min-device-pixel-ratio: 2),
    only screen and (min-device-pixel-ratio: 2) {
        &:after {
            transform: scaleX(0.5);
        }
    }

    /* 设备像素比为 3 */
    @media only screen and (-webkit-min-device-pixel-ratio: 3),
    only screen and (min-device-pixel-ratio: 3) {
        &:after {
            transform: scaleX(0.333333);
        }
    }
}
